package com.example.springapp.control;

import com.example.springapp.service.ShopService;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class ShopControl {
    @Autowired
    private ShopService shopService;


//    http://localhost:8080/shopCata
    @RequestMapping("/shopCata")
    @ResponseBody
    public String doShopCata(){
        List<String> lst = shopService.getShopCata();

        JsonArray ja = new JsonArray();
        for ( String str : lst ){
            ja.add(str);
        }
        JsonObject jo = new JsonObject();
        jo.add("total",ja);
        return jo.toString();
    }
}
